<?php get_header(); ?>
<div id="container">
	<div class="bg_banner">
        <div class="wrapper"> 
            <div class="grid24" style="margin-top:20px;">
                <div class="reservation">
                	<?php
                        $cabin_arr	= array(1 => '1 Cabin', 2 => '2 Cabins', 3 => '3 Cabins', 4 => '4 Cabins', 5 => '5 Cabins', 6 => '6 Cabins', 7 => '7 Cabins', 8 => '8 Cabins', 9 => '9 Cabins', 10 => '10 Cabins'); 
                        $url= get_permalink();
                    ?>  	
                    <h4>Cruise deals of the day</h4>
                    <script type="text/javascript">
					function checkSearch() {
						var cate = $('select#cate option:selected').val();
						if( cate == 0 ) {
							alert('Please select cruiser!');
							return false;
						}
						return true;
					}
					</script>
                    <form class="frm_reservation" action="" id="sCruise" method="post" onsubmit="return checkSearch();">
                        <div><label>Cruise Name:</label>
                        	<select name="cate" id="cate"><option value=0>Please select cruiser</option>
                            <?php
							$taxonomy = 'cruise_category';
							$mycat = $wpdb->get_results("SELECT t.term_id, name, slug
								FROM $wpdb->terms t
								INNER JOIN $wpdb->term_taxonomy tt ON t.term_id=tt.term_id 
								WHERE taxonomy='{$taxonomy}' AND parent=0");
							foreach( $mycat as $cate ) {
								echo '<optgroup label="'. $cate->name .'">';
								$mysql = $wpdb->get_results("SELECT p.ID, post_title, post_name
									FROM $wpdb->posts p 
									INNER JOIN $wpdb->term_relationships tr ON(p.ID = tr.object_id) 
									INNER JOIN $wpdb->term_taxonomy tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id)  
									WHERE tt.term_id=". $cate->term_id ." AND tt.taxonomy='{$taxonomy}' AND 
										post_type='cruise' AND post_status='publish' AND post_parent=0 ORDER BY post_title ASC;");
								foreach( $mysql as $post ) {
									echo '<option value="'. $post->ID .'">'. $post->post_title .'</option>';
								}
								echo '</optgroup>';
							} ?>
                            </select>
                        </div>  
                        <div id="trigger-checkin"><label>Departure Date:</label>
                            <span id="trigger-checkin">
                            <input type="text" id="check-in" name="checkin" value="<?php echo ((!empty($checkin)) ? $checkin : ''); ?>" required />
                            </span>
                             <script type="text/javascript">
                                Calendar.setup({ dateFormat: "%b %d, %Y", trigger: "trigger-checkin", inputField: "check-in",
                                min: 0, onSelect:function() { this.hide(); }});
								$(document).ready(function(){
									$("select#cate").change(function(){
										$('#package').html('');
										$('#package').css('background', 'url("<?php echo FOLDER_IMG; ?>/loading/loading15.gif") no-repeat scroll 0 10px #fff');
										var postData	= {
											url: 	'reload_Package', 
											postID:  $(this).val()
										};
										$.ajax({
											type: "POST",
											url: "<?php echo TEMPLATE_URL; ?>/actions.php",
											data: postData,
											cache: false,
											dataType: 'json',
											success: function(data){
												$('#package').css('background', '#fff');
												$('#package').html(data.optPackage);
												$('#sCruise').attr("action", data.formURL);
											}
										});
									});
								});
                            </script>
                        </div>
                       <!-- <div><input type="text" id="check-in" name="checkin"></div>-->
                        <div><label>Cruise Package:</label>
                        	 <select name="package" id="package">
								<option value="0">Please select cruise name</option>
                             </select>
                        </div>
                        <div><label>Cabin:</label>
                        	 <select name="numCabin">
								<?php foreach ($cabin_arr as $key => $value) : ?>
                                <option value="<?php echo $key; ?>"><?php echo $value; ?></option>
                                <?php endforeach; ?>
                             </select>
                        </div>
                        <div><img src="<?php echo FOLDER_IMG; ?>/icon_check.png" alt="guarantee price">
                        <?php
						$taxonomy = 'cruise_category';
						$mysql = $wpdb->get_col("SELECT count(*) AS sum 
							FROM $wpdb->posts p 
							INNER JOIN $wpdb->term_relationships tr ON(p.ID = tr.object_id) 
							INNER JOIN $wpdb->term_taxonomy tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id)  
							WHERE tt.taxonomy='{$taxonomy}' AND 
								post_type='cruise' AND post_status='publish' AND post_parent=0;");
						echo $sum = $mysql[0];
						?>
                         cruises, best price guarantee</div>   
                        <div style="margin-top:14px;"><input type="submit" class="btn_res" value="" name="booking"></div>   
                        <input type="hidden" name="isSearch" value="1" />
                    </form>
                </div>  <!-- reservation -->
                 <?php 
					global $table_prefix, $layout; 
					if( is_home() ): 
						$groupid = 1;
						$mysql = $wpdb->get_results("SELECT * FROM {$table_prefix}banner WHERE groupid=". $groupid);
						if( $mysql ) { ?>
                <div class="grid18" style="margin-left:10px;">
                    <div class="slider-wrapper theme-default">
                        <div id="slider" class="nivoSlider">
                            <?php foreach( $mysql as $adv ) {
                                ?><a href="<?php echo $adv->url; ?>"><img src="<?php echo $adv->source; ?>" alt="" /></a><?php
                            } ?>
                        </div>
                    </div>
                </div>
                <script type="text/javascript">
				$(window).load(function() {
					$('#slider').nivoSlider();
				});
				</script><?php
				}
				endif;
				?>                  
            </div><!-- grid 24 -->    
        </div><!-- wrapper -->
    </div><!-- bg banner -->
    
    <div class="wrapper">
    	<div class="grid24">
        	<aside class="grid6">
                <div class="box"><!-- support -->
                	<div class="box_title">
                    <h5>ONLINE SUPPORT</h5>
                    </div>
                    <div class="box_body">
                    <table style="width:100%; color:#1077e2; font-weight:bold;">
                        <tr>
                            <td colspan="2" style="text-align:center; font-weight:bold;">Sale Excutive</td>                            
                        </tr>
                        <tr>
                            <td>Mr.Danh</td> 
                            <td>Ms.Hang</td>                           
                        </tr>
                        <tr>
                            <td><a href="#"><img src="<?php echo FOLDER_IMG; ?>/yahoo.png" alt="yahoo"></a></td> 
                            <td><a href="#"><img src="<?php echo FOLDER_IMG; ?>/yahoo.png" alt="yahoo"></a></td>                           
                        </tr>
                        <tr>
                            <td><a href="#"><img src="<?php echo FOLDER_IMG; ?>/icon_skype.png" alt="skype"></a></td> 
                            <td><a href="#"><img src="<?php echo FOLDER_IMG; ?>/icon_skype.png" alt="skype"></a></td>                           
                        </tr>
                        <tr>
                        	<td colspan="2">8:30 - 17:00 (GMT +7)</td>                           
                        </tr>
                    </table>
                    </div>
                </div><!-- support -->
                
                 <div class="box"><!-- wwhy -->
                 	<div class="box_title">
                    	<h5>WHY BOOK WITH US</h5>
                    </div>
                    <div class="box_body">
                    <ul class="reason">
                        <li><a href="#">Trustworthy travel agency</a></li>
                        <li><a href="#">Prompt response</a></li>
                        <li><a href="#">We are local</a></li>
                        <li><a href="#">Ease of Planning</a></li>
                        <li><a href="#">Customer Satisfaction</a></li>
                    </ul>
                    </div>
                </div><!-- why -->
                
                <div class="box"><!-- 5 step -->
                	<div class="box_title">
                    	<h5>5 steps to book</h5>
                    </div>
                    <div class="box_body">
                    	<img src="<?php echo FOLDER_IMG; ?>/5step.png" alt="5 steps to book" style="margin-top:10px;">
                    </div>
                </div><!-- 5 step -->
                
				<?php 
                    global $table_prefix, $layout; 
                    if( is_home() ): 
                        $groupid = 2;
                        $mysql = $wpdb->get_results("SELECT * FROM {$table_prefix}banner WHERE groupid=". $groupid);
                        if( $mysql ) { ?>
                <div class="box2"><!-- partner -->
                    <h5>partner</h5>
                    <?php foreach( $mysql as $adv ) {
                            ?><img src="<?php echo $adv->source; ?>" alt="" style="width:230px; height:87px;" /><?php
                        } ?>
                    <!--<img src="<?php echo FOLDER_IMG; ?>/signature.jpg" alt="signature halong cruise" style="margin-top:10px;">
                    <img src="<?php echo FOLDER_IMG; ?>/paloma.jpg" alt="paloma cruise">-->
                </div><!-- partner -->
                <?php
                }
                endif;
                ?> 
                <?php 
					global $table_prefix, $layout; 
					if( is_home() ): 
						$groupid = 3;
						$mysql = $wpdb->get_results("SELECT * FROM {$table_prefix}banner WHERE groupid=". $groupid);
						if( $mysql ) { ?>
                <div class="grid18">
                    <div class="slider-image theme-default">
                        <h5>gallery</h5>
                            <div id="slider1" class="box2"><!-- gallery -->
                                <?php foreach( $mysql as $adv ) {
                                        ?><img src="<?php echo HOME_URL ?>/timthumb.php?src=<?php echo $adv->source; ?>&amp;w=230&amp;h=146&amp;q=100" alt="" /><?php
                                    } ?>
                                <!--<img src="<?php echo FOLDER_IMG; ?>/gallery.jpg" alt="gallery" style="margin-top:10px;">-->
                            </div><!-- gallery -->
                    </div>
                </div>
                <script type="text/javascript">
				$(window).load(function() {
					$('#slider1').nivoSlider();
				});
				</script>
                <?php
				}
				endif;
				?>    
                <?php 
					global $table_prefix, $layout; 
					if( is_home() ): 
						$groupid = 4;
						$mysql = $wpdb->get_results("SELECT * FROM {$table_prefix}banner WHERE groupid=". $groupid);
						if( $mysql ) { ?>
                <div class="box"><!-- wwhy -->
                    <div class="box_title">
                        <h5>links</h5>
                    </div>
                    <div class="box_body">
                    	<ul class="reason">
							<?php foreach( $mysql as $adv ) {
                                ?><li><a href="<?php echo $adv->url; ?>" target="_blank"><?php echo $adv->url; ?></a></li><?php
                            } ?>
                            <!--<li><a href="http://www.tnktravelvietnam.com/" target="_blank">tnktravelvietnam.com</a></li>
                        <li><a href="http://www.mekongcruisenow.com/" target="_blank">mekongcruisenow.com</a></li>
                        <li><a href="http://signaturehalongcruise.com/" target="_blank">signaturehalongcruise.com</a></li>
                        <li><a href="http://www.tnkvoyagesvietnam.com/" target="_blank">tnkvoyagesvietnam.com</a></li>
                        <li><a href="http://www.vietnamtailormadetours.com/" target="_blank">vietnamtailormadetours</a></li>-->
                  		</ul>
                  </div>
               </div><!-- why -->
               <?php
				}
				endif;
				?>
            </aside>
            <div class="grid18"><!-- content -->
            	<article class="welcome">
                <h2>Travel to Vietnam with tour and holiday packages of TNK Travel</h2>
					<?php 
                    $post = get_page(76);
                    $content = apply_filters('get_the_content', $post->post_content);
                    echo $content;
                    ?>
						<!--<h2>Travel to Vietnam with tour and holiday packages of TNK Travel</h2>
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus metus lectus, semper eget dictum nec, pretium non nisi. Nulla elit ante, tincidunt id augue sit amet, luctus malesuada diam. Suspendisse et luctus metus, at lacinia tortor. Sed adipiscing elit et bibendum porttitor. Nullam lobortis mauris purus, id rhoncus ante bibendum ut. Morbi tempor, tortor a ornare volutpat, ligula est vestibulum lorem, scelerisque sodales ipsum lorem vitae orci. Sed a neque sollicitudin, ultrices felis quis, porttitor arcu. Curabitur ac quam puru
                    --><div class="readmore">
                    	<a href="<?php echo get_permalink($page->ID); ?>">Read more</a>
                    </div>   
                    
                </article>
                
                <div class="clear"></div>
                
                <section class="grid18">
                	<h1>RECOMMEND TOURS</h1>
                    <div class="white_frame">
                    <?php 
					$args = array(
						'post_type'		=> 'cruise',
						'post_status' 	=> 'publish',
						'tax_query' => array(
							'taxonomy' 	=> 'cruise_category',
							'field' 	=> 'slug',
							'terms' 	=> $terms->slug,
							//'operator' 	=> 'IN'
							//$terms->term_id,
						),
						'meta_query' => array(
							array(
								'key' 	=> '_mb_top',
								'value' => 1
							)
						),
						'orderby' 		=> 'date',
						'order'			=> 'DESC',
						'showposts'		=> -1
					);
					query_posts($args);
					while (have_posts()) : the_post();
						//$thuoctinh_arr = get_post_meta( $post->ID, '_mb_attribute', true );
						//echo $thuoctinh_arr["tomtat"];
						?><article class="recommend">
							<figure class="featured-thumbnail">
								 <a href="<?php the_permalink(); ?>">
										<?php 
                                            if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                                              the_post_thumbnail('thumbnail');
                                            } 
                                         ?>
                                 </a>                                   
							</figure>
							<div class="grid12">
								<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></h1></a>
								<p>
                                <?php 
									$thuoctinh_arr = get_post_meta( $post->ID, '_mb_attribute', true );
									echo $thuoctinh_arr["tomtat"];
									//echo GetWords($thuoctinh_arr["tomtat"], 350);
								?>
                                </p>
							</div>                    	
						</article><?php
					endwhile;
					?>
                    </div> <!-- end white frame -->
                </section>
                <script type="text/javascript">
				function paginationOrder( idDiv, mLimit, mStart ) {
					$.ajaxSetup({cache:false});
					$('#pg_'+ idDiv).html(sprintf(loading, 15));
					var postData	= {
						url: 	'pagination_Order', 
						catID:  idDiv,
						start: 	mStart, 
						limit: 	mLimit
					};
					$.ajax({
						type: "POST",
						url: "<?php echo TEMPLATE_URL; ?>/actions.php",
						data: postData,
						cache: false,
						success: function(data){
							$('#pg_'+ idDiv).html(data);
						}
					});
					return false;
				}
				</script>
                <?php
				$taxonomy = 'cruise_category';
				$mycat = $wpdb->get_results("SELECT t.term_id, name, slug
					FROM $wpdb->terms t
					INNER JOIN $wpdb->term_taxonomy tt ON t.term_id=tt.term_id 
					WHERE taxonomy='{$taxonomy}' AND parent=0");
				foreach( $mycat as $cate ) {
					$start = 0;
					$limit = 3;

					$mysql = $wpdb->get_col("SELECT count(*) AS total 
						FROM $wpdb->posts p 
						INNER JOIN $wpdb->term_relationships tr ON(p.ID = tr.object_id) 
						INNER JOIN $wpdb->term_taxonomy tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id)  
						WHERE tt.term_id=". $cate->term_id ." AND tt.taxonomy='{$taxonomy}' AND 
							post_type='cruise' AND post_status='publish' AND post_parent=0;");
					$total = $mysql[0];
					$mysql = $wpdb->get_results("SELECT p.ID, post_title, post_name
						FROM $wpdb->posts p 
						INNER JOIN $wpdb->term_relationships tr ON(p.ID = tr.object_id) 
						INNER JOIN $wpdb->term_taxonomy tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id)  
						WHERE tt.term_id=". $cate->term_id ." AND tt.taxonomy='{$taxonomy}' AND 
							post_type='cruise' AND post_status='publish' AND post_parent=0 ORDER BY post_date DESC LIMIT {$start}, {$limit};");
				?>
                    <section class="grid18">
                    	<h1><a href="<?php echo get_term_link( $cate->slug, $taxonomy ); ?>"><?php echo $cate->name; ?></a></h1>
                        
                    	<div id="pg_<?php echo $cate->term_id; ?>" class="white_frame">
                        	<div class="top_cruise">
                                <div class="pagercontrol">
                                    <?php 
                                    if( $total > 0 )
                                        echo generate_pagination_ajax('paginationOrder', $cate->term_id, $total, $limit, $start). '&nbsp;';
                                    ?>
                                    <a href="<?php echo get_term_link( $cate->slug, $taxonomy ); ?>">View all</a>
                                </div>
                            </div><!-- top cruise-->
                            
                            <?php
                            $i = 1;
                            foreach( $mysql as $cruises ) {
                                $thuoctinh_arr = get_post_meta( $cruises->ID, '_mb_attribute', true );
                                ?>
                                <article class="cruise"<?php echo (($i == 3) ? '' : ' style="margin-right:10px;"'); ?>>
                                    <figure class="featured-thumbnail">
                                         <a href="<?php echo get_permalink($cruises->ID); ?>"><?php echo get_the_post_thumbnail($cruises->ID, 'thumbnail'); ?></a>                                   
                                    </figure>
                                    <h3><a href="<?php echo get_permalink($cruises->ID); ?>"><?php echo $cruises->post_title; ?></a></h3>
                                    <p><?php echo GetWords($thuoctinh_arr["tomtat"], 200); ?></p>                        
                                </article>
                                <?php
                                if( $i == 3 )
                                    $i = 1;
                                $i ++ ;
                            }
						echo '</div>';
					echo '</section>';
				} ?>
            
            </div><!-- content -->
            
        </div><!-- grid 24 -->
        
    </div><!-- wrapper -->
   
</div> <!-- container -->
<?php get_footer(); ?>